home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / upc12bs1.zip / UUCICO / prtyos2.c < prev    next >
C/C++ Source or Header  |  1993-10-03  |  5KB  |  141 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       p r t y o s 2 . c                                            */
  3. /*                                                                    */
  4. /*       Set task priority for OS/2 tasks under UUPC/extended         */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Changes Copyright (c) 1989-1993 by Kendra Electronic            */
  9. /*    Wonderworks.                                                    */
  10. /*                                                                    */
  11. /*    All rights reserved except those explicitly granted by the      */
  12. /*    UUPC/extended license agreement.                                */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: prtyos2.c 1.3 1993/10/03 22:34:33 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: prtyos2.c $
  24.  * Revision 1.3  1993/10/03  22:34:33  ahd
  25.  * Alter format of numbers printed
  26.  *
  27.  * Revision 1.2  1993/09/29  04:52:03  ahd
  28.  * Pass priority values as parameters
  29.  *
  30.  * Revision 1.1  1993/09/25  03:07:56  ahd
  31.  * Initial revision
  32.  *
  33.  */
  34.  
  35. /*--------------------------------------------------------------------*/
  36. /*                        System include files                        */
  37. /*--------------------------------------------------------------------*/
  38.  
  39. #include <stdio.h>
  40.  
  41. #define INCL_NOPMAPI
  42. #define INCL_BASE
  43. #include <os2.h>
  44.  
  45. /*--------------------------------------------------------------------*/
  46. /*                    UUPC/extended include files                     */
  47. /*--------------------------------------------------------------------*/
  48.  
  49. #include "lib.h"
  50. #include "pos2err.h"
  51.  
  52. /*--------------------------------------------------------------------*/
  53. /*                          Local variables                           */
  54. /*--------------------------------------------------------------------*/
  55.  
  56. currentfile();
  57.  
  58. #ifndef __OS2__
  59. typedef USHORT APIRET ;  // Define older API return type
  60. #endif
  61.  
  62. #ifdef __OS2__
  63. static ULONG usPrevPriority;
  64. #else
  65. static USHORT usPrevPriority;
  66. #endif
  67.  
  68. static boolean restore = FALSE;
  69.  
  70. /*--------------------------------------------------------------------*/
  71. /*       s e t P r t y                                                */
  72. /*                                                                    */
  73. /*       Set priority to configuration defined value                  */
  74. /*--------------------------------------------------------------------*/
  75.  
  76. void setPrty( const KEWSHORT priorityIn, const KEWSHORT prioritydeltaIn )
  77. {
  78.    USHORT priority = (priorityIn == 999) ?
  79.                            PRTYC_FOREGROUNDSERVER : (USHORT) priorityIn;
  80.    USHORT prioritydelta = (prioritydeltaIn == 999) ?
  81.                            0 : (USHORT) (prioritydeltaIn + PRTYD_MINIMUM);
  82.  
  83.    APIRET rc;
  84.  
  85. #ifdef __OS2__
  86.  
  87.    PTIB ptib;
  88.    PPIB ppib;
  89.  
  90.    rc = DosGetInfoBlocks( &ptib, &ppib);
  91.    if ( !rc )
  92.       usPrevPriority = (ptib->tib_ptib2)->tib2_ulpri;
  93. #else
  94.    rc = DosGetPrty(PRTYS_PROCESS, &usPrevPriority, 0);
  95. #endif
  96.  
  97.    if (rc)
  98.    {
  99.       printOS2error( "DosGetPrty", rc );
  100.       panic();
  101.    } /*if */
  102.    else
  103.       restore = TRUE;
  104.  
  105.    rc = DosSetPrty(PRTYS_PROCESS, priority, prioritydelta, 0);
  106.  
  107.    if (rc)
  108.    {
  109.       printmsg(0,"setPrty: Unable to set priority %hu,%hu for task",
  110.                    priority, prioritydelta);
  111.       printOS2error( "DosSetPrty", rc );
  112.  
  113.    } /*if */
  114.  
  115. } /* SetPrty */
  116.  
  117. /*--------------------------------------------------------------------*/
  118. /*       r e s e t P r t y                                            */
  119. /*                                                                    */
  120. /*       Restore priority saved by SetPrty                            */
  121. /*--------------------------------------------------------------------*/
  122.  
  123. void resetPrty( void )
  124. {
  125.  
  126.    APIRET rc;
  127.  
  128.    if ( !restore )
  129.       return;
  130.  
  131.    rc = DosSetPrty(PRTYS_PROCESS,
  132.                    usPrevPriority >> 8 ,
  133.                    usPrevPriority & 0xff, 0);
  134.  
  135.    if (rc)
  136.       printOS2error( "DosSetPrty", rc );
  137.  
  138.    restore = FALSE;
  139.  
  140. } /* resetPrty */
  141.